<template>
	<view class="main">
		<u-tabs :current="current" :list="tabList" @click="seleTab"></u-tabs>
		<u-empty v-if="list.length == 0 && isShow" mode="data" icon="http://cdn.uviewui.com/uview/empty/data.png" text="暂无订单"></u-empty>
		<ul class="list">
			<li v-for="(item, index) in list" :key="index">
				<view class="one">
					<view class="msg">订单编号：{{ item.orderid }}</view>
					<view class="tag">
						<span>{{ item.status_text }}</span>
						<!-- <span>待发货</span>
						<span>待收货</span>
						<span>已完成</span> -->
					</view>
				</view>
				<view class="two" v-for="(sitem, index) in item.product_list" :key="index">
					<view class="img">
						<image :src="sitem.image" mode=""></image>
					</view>
					<view class="info msg">
						<view class="tit">
							{{ sitem.product_name }}
						</view>
						<view class="sku">
							<span v-for="(ssitem, index) in sitem.attrs">{{ item }}</span>
						</view>
					</view>
					<view class="info right">
						<view class="price">￥{{ sitem.price }}</view>
						<view class="num">
							<image src="@/static/img/ride.png" mode=""></image>
							<span>{{ sitem.num }}</span>
						</view>
					</view>
				</view>
				<view class="the">
					<view v-if="item.status == 0" class="btn on" @tap.stop="routerTo(`/pages/pageB/order/selePay?tag=${item.orderid}`)">去支付</view>
					<!-- <view v-if="item.status == 20" class="btn on" @tap.stop="routerTo('/pages/pageB/order/comment')">去评价</view> -->
				</view>
			</li>
		</ul>
	</view>
</template>

<script>
import { Productorder } from '@/api/user.js';
export default {
	data() {
		return {
			isShow: false,
			tabList: [
				{
					name: '全部',
					id: -1
				},
				{
					name: '待付款',
					id: 0
				},
				{
					name: '待发货',
					id: 1
				},
				{
					name: '已发货',
					id: "10,11,12"
				},
				{
					name: '已完成',
					id: 20
				},
				{
					name: '其他',
					id: "13,14,15,16,17"
				}
			],
			current: 0,
			data: {
				page_size: 15,
				status: -1,
				page: 1
			},
			list: [],
			last_page: ''
		};
	},
	onLoad(e) {
		console.log(e)
		this.data.status = e.status;
		this.tabList.forEach((item, index) => {
			if (item.id == e.status) {
				this.current = index;
			}
		});
		this.getList();
	},
	onReachBottom() {
		if (this.data.page == this.last_page) {
			uni.showToast({
				title: '已经是最后一页了',
				icon: 'none'
			});
		} else {
			this.data.page++;
			this.getList();
		}
	},
	methods: {
		seleTab(e) {
			this.data.status = e.id;
			this.data.page = 1;
			this.getList();
		},
		async getList() {
			this.isShow = false;
			if (this.data.page == 1) {
				this.list = [];
			}
			let res = await Productorder(this.data);
			this.last_page = res.data.list.last_page;
			res.data.list.data.forEach((item) => {
				this.list.push(item);
			});
			this.isShow = true;
			console.log(this.list)
		},
		routerTo(url) {
			uni.navigateTo({
				url: url
			});
		}
	}
};
</script>

<style lang="scss" scoped>
.main {
	min-height: calc(100vh - 44px);
	background-color: #f8f9fc;

	/deep/.u-tabs {
		background-color: #fff;
	}

	.tab {
		background-color: #fff;
		padding: 20px 25px 0;
		width: 100%;
		display: flex;
		justify-content: space-between;

		li {
			font-size: 13px;
			color: #9c9c9c;
			display: flex;
			flex-direction: column;
			align-items: center;

			.msg {
				margin-bottom: 15px;
			}

			.hr {
				width: 17px;
				height: 2px;
			}
		}

		.active {
			color: #3aa2ff;
			font-weight: 700;

			.hr {
				background-color: #3aa2ff;
			}
		}
	}

	.list {
		padding: 15px;

		li {
			background-color: #fff;
			border-radius: 10px;
			padding: 10px 15px;
			margin-bottom: 15px;

			.one {
				display: flex;
				justify-content: space-between;
				align-items: center;
				margin-bottom: 10px;

				.msg {
					font-size: 11px;
					color: #666666;
				}

				.tag {
					font-size: 14px;
					color: #3aa2ff;
				}
			}

			.two {
				display: flex;
				justify-content: space-between;
				align-items: center;

				.img {
					image {
						width: 80px;
						height: 70px;
						border-radius: 5px;
					}
				}

				.msg {
					flex: 1;
					margin: 0 10px 0 5px;
				}

				.right {
					align-items: end;
					font-size: 13px;
					color: #666666;
				}

				.info {
					display: flex;
					flex-direction: column;
					justify-content: space-between;
					height: 70px;
					font-size: 14px;
					.num {
						display: flex;
						align-items: center;
						image {
							width: 15px;
							height: 15px;
						}
					}

					.tit {
						color: #232323;
						overflow: hidden;
						text-overflow: ellipsis;
						-webkit-line-clamp: 2;
						display: -webkit-box;
						-webkit-box-orient: vertical;
					}

					.sku {
						color: #666666;
					}
				}
			}

			.the {
				display: flex;
				justify-content: right;
				margin-top: 10px;

				.btn {
					font-size: 14px;
					width: 80px;
					padding: 5px 0;
					text-align: center;
					border-radius: 1000px;
				}

				.del {
					color: #7b7b7b;
					border: 1px solid #7b7b7b;
					margin-right: 10px;
				}

				.on {
					color: #fff;
					background-color: #3aa2ff;
				}
			}
		}
	}
}
</style>